home *** CD-ROM | disk | FTP | other *** search
- /********************************/
- /* */
- /* BitMapper Code */
- /* Copyright 1992, Dave Mark */
- /* */
- /********************************/
-
- #define kMoveToFront (WindowPtr)-1L
-
- const short kBackgroundPictID = 128;
- const short kForegroundPictID = 129;
-
-
- /***************/
- /* Functions */
- /***************/
-
- void ToolboxInit( void );
- WindowPtr WindowInit( void );
- PicHandle LoadPicture( short resID );
- GrafPtr CreateBitMap( const Rect *rPtr );
-
-
- /****************** main ***************************/
-
- void main( void )
- {
- Rect r;
- GrafPtr backPortPtr, forePortPtr, mixerPortPtr;
- WindowPtr window;
- PicHandle backPict, forePict;
- Point p;
-
- ToolboxInit();
- window = WindowInit();
-
- backPict = LoadPicture( kBackgroundPictID );
- r = (**backPict).picFrame;
- OffsetRect( &r, -r.left, -r.top );
-
- backPortPtr = CreateBitMap( &r ); /* Leaves backPortPtr as current port */
- DrawPicture( backPict, &r );
-
- mixerPortPtr = CreateBitMap( &r ); /* Leaves mixerPortPtr as current port */
-
- forePict = LoadPicture( kForegroundPictID );
- r = (**forePict).picFrame;
- OffsetRect( &r, -r.left, -r.top );
-
- forePortPtr = CreateBitMap( &r ); /* Leaves forePortPtr as current port */
- DrawPicture( forePict, &r );
-
- HideCursor();
-
- while ( !Button() )
- {
- CopyBits( &(backPortPtr->portBits), &(mixerPortPtr->portBits),
- &(backPortPtr->portBits.bounds), &(mixerPortPtr->portBits.bounds),
- srcCopy, nil );
-
- GetMouse( &p );
- SetPort( window );
- GlobalToLocal( &p );
- r = forePortPtr->portBits.bounds;
- OffsetRect( &r, p.h, p.v );
-
- CopyBits( &(forePortPtr->portBits), &(mixerPortPtr->portBits),
- &(forePortPtr->portBits.bounds), &r,
- srcOr, nil );
-
- CopyBits( &(mixerPortPtr->portBits), &(window->portBits),
- &(mixerPortPtr->portBits.bounds), &(window->portRect),
- srcCopy, nil );
- }
- }
-
-
- /****************** ToolboxInit *********************/
-
- void ToolboxInit( void )
- {
- InitGraf( &thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( nil );
- InitCursor();
- }
-
-
- /****************** WindowInit ***********************/
-
- WindowPtr WindowInit( void )
- {
- WindowPtr window;
- PicHandle pic;
- Rect r;
-
- pic = LoadPicture( kBackgroundPictID );
- r = (**pic).picFrame;
-
- OffsetRect( &r, 20 - r.left, 50 - r.top );
-
- window = NewWindow( nil, &r, "\pBitMapper", true, noGrowDocProc,
- kMoveToFront, false, 0L );
-
- return( window );
- }
-
-
- /****************** LoadPicture *********************/
-
- PicHandle LoadPicture( short resID )
- {
- PicHandle picture;
-
- picture = GetPicture( resID );
-
- if ( picture == nil )
- {
- SysBeep( 10 ); /* Couldn't load the PICT resource!!! */
- ExitToShell();
- }
- }
-
-
- /****************** CreateBitMap *********************/
-
- GrafPtr CreateBitMap( const Rect *rPtr )
- {
- short i;
- BitMap *bPtr;
- GrafPtr g;
-
- g = (GrafPtr)NewPtr( sizeof(GrafPort) );
- if ( g == nil )
- SysBeep(20);
-
- bPtr = (BitMap *)NewPtr( sizeof( BitMap ) );
- if ( bPtr == nil )
- SysBeep( 20 );
- bPtr->bounds = *rPtr;
-
- bPtr->rowBytes = (rPtr->right - rPtr->left + 7) /8;
- /* i = bPtr->rowBytes / 2;
- if ( (2 * i) != bPtr->rowBytes )
- bPtr->rowBytes ++;*/
-
- i = rPtr->bottom - rPtr->top;
- bPtr->baseAddr = NewPtr( bPtr->rowBytes * i );
-
- if ( bPtr->baseAddr == nil )
- SysBeep( 20 );
-
- OpenPort( g );
- SetPortBits( bPtr );
-
- return( g );
- }